package com.github.template;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @ClassName HelloworldAutoConfiguration
 * @Description TODO
 * @Author shuang669539827@163.com
 * @Date2019/5/24 16:18
 * @Version v1.0
 **/
@Configuration
@ConditionalOnClass({GeneratorService.class})
@EnableConfigurationProperties(TemplateConfigProperties.class)
public class TemplateAutoConfiguration {

    @Resource
    private TemplateConfigProperties templateConfigProperties;

    /**
     * @ConditionalOnMissingBean(HelloworldService.class)当容器中没有这个bean的时候就创建
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(GeneratorService.class)
    public GeneratorService generatorService(){
        GeneratorService generatorService = new GeneratorService();
        generatorService.setDir(templateConfigProperties.getDir());
        generatorService.setNames(templateConfigProperties.getNames());
        return generatorService;
    }

}
